<!DOCTYPE html>
<meta charset="utf-8">
<head>
  <title>cr-audit-commits Status Page</title>
    <style type="text/css"/>
      body {
        font-family: Roboto, Arial, sans-serif;
      }

      td {
        vertical-align: top;
        padding: 10px;
      }

      h3 {
        text-align: center;
        font-size: 28px;
      }

      table {
        margin: 0 auto;
      }

      table table {
        margin: 0;
      }

      table table td{
        border-bottom: 1px solid #DDDDDD;
      }

      .red-status{
        color: #9A2617;
        font-weight: bold;
      }
      .green-status{
        color: #829356;
      }

      .message{
        word-wrap: break-word;
        max-width: 350px;
        color: #0C374D;
        font-size: 12px;
        font-family: monospace;

      }

      .section {
        margin: 20px auto;
        padding: 20px;
        background: linear-gradient(to bottom right, #DCE5F8, #FFFFFF);
        max-width: 1500px;
        box-shadow: 1px 1px 5px #888888;
        border-radius: 20px;
    }
  </style>
</head>

<body>
  {{if .Error}}
    <h3 class="red-status">{{.Error}}</h3>
  {{end}}
  <div class="section">
    <h3>Monitored Repositories</h3>
    <table>
      <tr>
        <th> Repository </th>
        <th> Link to Audit Status </th>
      </tr>
      {{range $rs := .RepoStates}}
        <tr>
          <td><a href="{{$rs.RepoURL}}">{{$rs.RepoURL}}</a></td>
          <td><a href="/view/status?refUrl={{$rs.RepoURL}}"> Audit Status </a></td>
        </tr>
      {{end}}
    </table>
  </div>

  {{if (or .RefUrl .Commits)}}
    <div class="section">
      {{if .RefUrl}}
        <h3>Status for {{.RefUrl}}</h3>
        <table>
          <tr>

            {{if .LastRelevant}}
              <td> Last Relevant Commit
                <a href="{{.RepoConfig.BaseRepoURL}}/+/{{.LastRelevant}}">{{printf "%.8s" .LastRelevant}}</a>
                {{if not .LastRelevantTime.IsZero}}
                  ({{timeAgo .LastRelevantTime}})
                {{end}}
              </td>
            {{end}}

            {{if .LastScanned}}
              <td>
                Last Scanned Commit
                <a href="{{.RepoConfig.BaseRepoURL}}/+/{{.LastScanned}}">{{printf "%.8s" .LastScanned}}</a>
                {{if not .LastScannedTime.IsZero}}
                  ({{timeAgo .LastScannedTime}})
                {{end}}
              </td>
            {{end}}
            <td>
              Previous alerts:
              <a href="https://bugs.chromium.org/p/{{.RepoConfig.MonorailProject}}/issues/list?can=1&q=reporter%3Acr-audit-commits%40appspot.gserviceaccount.com">
                Monorail link
              </a>
            </td>

          </tr>
        </table>
      {{end}}

      {{if .Commits}}
        <h3>Most recent audited commits</h3>
        <table>
          <tr>
            <th>Commit</th>
            <th>Commit time</th>
            <th>Status</th>
            <th>Alert</th>
          </tr>
          {{$repo := .RepoConfig.BaseRepoURL}}
          {{$rc := .RepoConfig}}
          {{range .Commits}}
            <tr>
              <td width="350">
                <a href="{{$repo}}/+/{{.CommitHash}}">
                  {{printf "%.8s" .CommitHash}}
                  &#9672; {{commitSubject .CommitMessage}}
                </a>
              </td>
              <td width="200">
                {{timeAgo .CommitTime}}
              </td>
              <td>
                <table>
                  <tr>
                    <td align="center" class="{{.Status.ColorCode}}" colspan="3">
                       {{.Status.ToString}}
                    </td>
                  </tr>
                  {{range .Result}}
                    <tr>
                      <td>{{.RuleName}}</td>
                      <td class="{{.RuleResultStatus.ColorCode}}" width="300">
                        {{.RuleResultStatus.ToString}}
                        {{if .Message}}
                          <p class="message">{{.Message}}</p>
                        {{end}}
                      </td>
                    </tr>
                  {{end}}
                </table>
              </td>
              <td>
                {{range .NotificationStates}}
                  {{if (isBug .)}}
                    <a href="https://bugs.chromium.org/p/{{$rc.MonorailProject}}/issues/detail?id={{issueID .}}">Issue {{.IssueID}}</a>
                    <br>
                  {{end}}
                {{end}}
              </td>
            </tr>
          {{end}}
        </table>
      {{end}}
    </div>
  {{end}}
</body>
